import axios from 'axios';
import * as url from '../../../http/api'
import http from '../../../http/http'

const actions = {
    /*营业管理分页查询*/
    searchSalesAct({commit}, obj) {
        return http({
            url: url.businessManagementPage,
            method: 'post',
            data: obj,
        }).then(resp => {
            console.log(resp);
            commit("searchSalesAct", resp.data)
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*添加排班*/
    addArrangeAct({commit}, obj) {
        return http({
            url: url.employeeManagementAdd,
            method: 'post',
            data: obj
        }).then(resp => {
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*排班分页查询*/
    pageSelectAct({commit}, obj) {
        return http({
            url: url.employeeManagementPage,
            method: 'post',
            data: {
                currentPage: obj.currentPage,
                pageSize: obj.pageSize,
            }
        }).then(resp => {
            // console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*条件查询分页*/
    searchPageAct({commit}, obj) {
        return http({
            url: url.employeeManagementSelect,
            method: 'post',
            data: {
                searchName: obj.searchName,
                currentPage: obj.currentPage,
                pageSize: obj.pageSize,
            }
        }).then(resp => {
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*修改排班信息*/
    fixArrangeAct({commit}, obj) {
        return http({
            url: url.employeeManagementUpdate,
            method: 'post',
            data: {
                arrangeId: obj.arrangeId,
                workDay: obj.workDay,
                timeSlot: obj.timeSlot,
                name: obj.name,
            }
        }).then(resp => {
            // console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*删除排班信息*/
    deleteArrangeAct({commit}, index) {
        return http({
            url: url.employeeManagementDelete,
            method: 'post',
            data: {
                arrangeId: index,
            }
        }).then(resp => {
            // console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*会员分页查询*/
    invoPageSelectAct({commit}, obj) {
        return http({
            url: url.memberManagementPage,
            method: 'post',
            data: obj
        }).then(resp => {
            console.log(resp.data);
            commit('invoPageSelectAct', resp.data)
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*会员条件查询分页*/
    invoSearchPageAct({commit}, obj) {
        return http({
            url: url.memberManagementSelect,
            method: 'post',
            data: {
                searchName: obj.searchName,
                currentPage: obj.currentPage,
                pageSize: obj.pageSize,
            }
        }).then(resp => {
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*添加会员信息*/
    addMemberCommitAct({commit}, obj) {
        console.log(obj);
        return http({
            url: url.memberManagementAdd,
            method: 'post',
            data: obj
        }).then(resp => {
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*修改会员信息*/
    fixMemberCommitAct({commit}, obj) {
        return http({
            url: url.memberManagementUpdate,
            method: 'post',
            data: obj,

        }).then(resp => {
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*删除会员信息*/
    deleteMemberCommitAct({commit}, obj) {
        return http({
            url: url.memberManagementDelete,
            method: 'post',
            data: {
                number: obj.number,
            }
        }).then(resp => {
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*会员充值*/
    addMoneyCommitAct({commit}, obj) {
        return http({
            url: url.memberManagementRecharge,
            method: 'post',
            data: {
                number: obj.number,
                money: obj.money,
            }
        }).then(resp => {
            commit('addMoneyCommitAct',resp.data)
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*合并会员*/
    combineCommitAct({commit}, obj) {
        return http({
            url: url.memberManagementMerge,
            method: 'post',
            data: {
                number: obj.number,
                deputyId: obj.deputyId,
            }
        }).then(resp => {
            console.log(resp);
            return resp.data
        }).catch(err => {
            console.log(err);
        })
    },
    /*设置点击的下标*/
    setCheckedRowIndex({commit}, index) {
        commit('setCheckedRowIndex', index)
    },


};
const mutations = {
    addMoneyCommitAct(state, obj){

    },
    setCheckedRowIndex(state, index) {
        state.checkedRowIndex = index
        state.fixName = state.pageData[index].name
        state.fixIdCard = state.pageData[index].idCard
        state.fixStateSelect = state.pageData[index].state
        state.fixTel = state.pageData[index].tel
        state.fixScore = state.pageData[index].score
        state.number = state.pageData[index].number

    },
    searchSalesAct(state, obj) {

    },
    invoPageSelectAct(state, obj) {

        state.pageData = obj.MemberList
    },

};
const state = {
    checkedRowIndex: 0,
    fixName: '',
    fixIdCard: '',
    fixStateSelect: '',
    fixTel: '',
    fixScore: '',
    number:'',
    pageData: [{}],//数据结构必须和前后文一致
};
export default {
    actions,
    mutations,
    state
}
